home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
PROG_TOO
/
C013.ZIP
/
WHAT.C
< prev
next >
Wrap
Text File
|
1990-01-19
|
2KB
|
83 lines
/********************************************************************
* C Users Group (U.K) C Source Code Library File CUGLIB.013 *
* Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd. *
* Edgbaston, Birmingham B15 2QN ENGLAND *
********************************************************************
* File name: what.c
* Program name:what
* Source of file: Ron Wellstead
* Purpose: An MS-DOS copy of the UNIX utility of the same name.
* Changes: <who what when & why major changes have been made>
********************************************************************/
/*
*
* @(#) what.c 1.2 87/07/27
*
* UNIX style what utility for dos
*
* copyright (c) 1987 Ron Wellsted.
* This software is provided on the understanding that it is
* NOT to be used for commercial gain. It may be freely distributed
* in source or object form among amateur and hobby computer users ONLY!
*
* displays on stdout the what-strings in file(s)
* usage: what files...
* written for Microsoft C, link with setargv.obj to expand wildcards
*/
#include <stdio.h>
#include <ctype.h>
#define FALSE 0
#define TRUE 1
char what[]="@(#) what VR 1.0.0 15 Jul 1987";
main(argc, argv)
int argc;
char **argv;
{
FILE *fp;
if (argc == 1) { /* no args; error */
fprintf(stderr,"usage: what filespec....\n");
exit(1);
} else {
while (--argc > 0) {
if ((fp = fopen(*++argv, "rb")) == NULL)
fprintf(stderr,"what: Can't open %s\n",*argv);
else {
printf("%s :\n",*argv);
filescan(fp);
fclose(fp);
}
}
}
}
filescan(fp) /* scan file fp for "@(#)" & output asciz string */
FILE *fp;
{
int ch,state=0;
while ((ch=getc(fp))!=EOF) {
if ((state==0)&&(ch=='@'))
++state;
else if ((state==1)&&(ch=='@')) ;
else if ((state==1)&&(ch=='('))
++state;
else if ((state==2)&&(ch=='#'))
++state;
else if ((state==3)&&(ch==')'))
++state;
else if ((state==4)&&(ch!='\0')&&(ch!='\n'))
putchar(ch);
else if (state==4) {
putchar('\n');
state=0;
}
else state=0;
}
}